<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    //
    protected $table='dg_order';

    protected $fillable=['user_id','sn','total'];

    const STATUS = [
        'CREAT_ORDER'   => 1, //已下单
        'HAVED_SEND'    => 2, //已发货
        'WAIT_TAKE'     => 3, //带提货
        'HAVED_TAKE'    => 4  //已提货
    ];
    const PAYSTATUS = 1;
    const UnPAYSTATUS = 0;
     /**
     * 获取博客文章的评论。
     */
    public function orderProducts()
    {
        return $this->hasMany('App\Models\OrderProduct','order_id','id');
    }
    public function orderAddress()
    {
        return $this->hasOne('App\Models\OrderAddress','order_id','id');
    }

    public function user()
    {
    	return $this->hasOne('App\Models\User','id','user_id');
    }

     /**
     * 属于订单的的商品。
     */
    public function products()
    {
        return $this->belongsToMany('App\Models\Product',(new \App\Models\OrderProduct())->getTable(),'order_id','product_id');
    }
}
